﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using SSPharma.Biz.HeThong;

namespace SSPharma.View.HeThong
{
    /// <summary>
    /// Interaction logic for ucHT_ImportExcel.xaml
    /// </summary>
    public partial class ucHT_ImportExcel : UserControl
    {
        private DataSet ds;
        private string strFormName;
        private BizImportExcel _BizImportExcel;
        public ucHT_ImportExcel()
        {
            InitializeComponent();
            _BizImportExcel = new BizImportExcel();
            strFormName = txtFormName.Text;
        }

        #region Event
        private void btnChonFile_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog fdlg = new Microsoft.Win32.OpenFileDialog();
            fdlg.Reset();
            fdlg.Title = "Select file";
            fdlg.InitialDirectory = @"c:\";
            fdlg.FileName = txtFileName.Text;
            fdlg.Filter = "Excel files|*.xls;*.xlsx;|All Files(*.*)|*.*";//Sheet(*.xlsx)|*.xlsx
            fdlg.FilterIndex = 1;
            fdlg.RestoreDirectory = true;
            bool bResult = (bool)fdlg.ShowDialog();
            if (bResult)
            {
                txtFileName.Text = fdlg.FileName;
                ShowSheet(txtFileName.Text);
            }
        }
        private void g_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            #region freeze column
            if ((((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) && ((Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt)) && (e.Key == Key.F))
            {
                int columnDisplayIndex = g.CurrentCell.Column.DisplayIndex + 1;
                g.FrozenColumnCount = columnDisplayIndex;
            }
            #endregion
        }
        private void g_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = (e.Row.GetIndex() + 1).ToString();
        }

        private void btnLayMau_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btnKiemTraDuLieu_Click(object sender, RoutedEventArgs e)
        {

        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {

        }
        #endregion

        #region Function
        public void ShowSheet(string strFileName)
        {
            try
            {

                //var formsheet = new FormSheet(_BizImportExcel.GetListSheet(strFileName));
                //formsheet.IdentityUpdated += new FormSheet.IdentityUpdate(Search_Form);
               // formsheet.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }
        private void Search_Form(string NameSheetReturn)
        {
            string str = NameSheetReturn;
            this.Import(NameSheetReturn);
        }
        private void Import(string namesheet)
        {
            try
            {

                //DataTable dt = _ExportExcel.GetDataTableExcel(txtFileName.Text, namesheet);
                //ds.Tables.Remove(ds.Tables[0]);
                //DataTable dtcopy = dt.Copy();
                //dtcopy.TableName = "TB_VatTu";
                //foreach (DataRow row in dtcopy.Rows)
                //{
                //    row.SetAdded();
                //}
                //ds.Tables.Add(dtcopy);
                //g.DataContext = ds.Tables["TB_VatTu"].AsDataView();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }


        #endregion
    }
}
